 <%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.util.List" %>
<%@ page import="com.example.model.Post" %>
<!DOCTYPE html>
<html>
<head>
    <title>博客列表</title>
    <style>
        body { font-family: Arial, sans-serif; margin: 20px; }
        .post { border-bottom: 1px solid #ccc; padding: 10px 0; }
    </style>
</head>
<body>
    <h1>博客列表</h1>
    <a href="${pageContext.request.contextPath}/posts/new">写新博客</a>
    
    <% for (Post post : (List<Post>)request.getAttribute("posts")) { %>
        <div class="post">
            <h2><%= post.getTitle() %></h2>
            <p><%= post.getContent() %></p>
            <p>发布时间: <%= post.getCreatedAt() %></p>
            <a href="${pageContext.request.contextPath}/posts/edit?id=<%= post.getId() %>">编辑</a>
            <form style="display: inline;" method="post" action="${pageContext.request.contextPath}/posts">
                <input type="hidden" name="action" value="delete">
                <input type="hidden" name="id" value="<%= post.getId() %>">
                <input type="submit" value="删除" onclick="return confirm('确定要删除吗？')">
            </form>
        </div>
    <% } %>
</body>
</html> 